//#include <stdio.h>
//#include <stdlib.h>
//
//typedef long long ll;
//
//ll n, d;
//ll h[50005];
//ll ans[50005];
//
//int check(ll X) 
//{
//    ll current = 0;
//    int index = 0;
//    for (int day = 1; day <= d; day++)
//    {
//        current /= 2;
//        while (current < X && index < n) 
//        {
//            current += h[index];
//            index++;
//        }
//        if (current < X) 
//        {
//            return 0;
//        }
//    }
//    return 1;
//}
//
//int main() 
//{
//    scanf_s("%lld %lld", &n, &d);
//    ll sum = 0;
//    for (int i = 0; i < n; i++) 
//    {
//        scanf_s("%lld", &h[i]);
//        sum += h[i];
//    }
//
//    ll low = 0, high = sum;
//    ll bestX = 0;
//    while (low <= high) 
//    {
//        ll mid = (low + high) / 2;
//        if (check(mid)) 
//        {
//            bestX = mid;
//            low = mid + 1;
//        }
//        else 
//        {
//            high = mid - 1;
//        }
//    }
//
//    ll current = 0;
//    int index = 0;
//    for (int day = 1; day < d; day++) 
//    {
//        current /= 2;
//        while (current < bestX && index < n) 
//        {
//            current += h[index];
//            ans[index] = day;
//            index++;
//        }
//    }
//    while (index < n) 
//    {
//        ans[index] = d;
//        index++;
//    }
//
//    printf("%lld\n", bestX);
//    for (int i = 0; i < n; i++)
//    {
//        printf("%lld\n", ans[i]);
//    }
//
//    return 0;
//}

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

ll n, m;
ll* r;
ll* d, * s, * t;

int check(ll x) 
{
    ll* diff = (ll*)calloc(n + 2, sizeof(ll));
    for (ll i = 1; i <= x; i++)
    {
        diff[s[i]] += d[i];
        if (t[i] + 1 <= n) 
        {
            diff[t[i] + 1] -= d[i];
        }
    }
    ll current = 0;
    for (ll i = 1; i <= n; i++) 
    {
        current += diff[i];
        if (current > r[i]) 
        {

            free(diff);
            return 0;
        }
    }
    free(diff);
    return 1;
}

int main()
{
    scanf_s("%lld %lld", &n, &m);
    r = (ll*)malloc((n + 1) * sizeof(ll));
    for (ll i = 1; i <= n; i++)
    {
        scanf_s("%lld", &r[i]);
    }
    d = (ll*)malloc((m + 1) * sizeof(ll));
    s = (ll*)malloc((m + 1) * sizeof(ll));
    t = (ll*)malloc((m + 1) * sizeof(ll));
    for (ll i = 1; i <= m; i++)
    {
        scanf_s("%lld %lld %lld", &d[i], &s[i], &t[i]);
    }

    ll left = 1, right = m + 1;
    while (left < right)
    {
        ll mid = (left + right) / 2;
        if (check(mid))
        {
            left = mid + 1;
        }
        else {
            right = mid;
        }
    }

    if (left > m) 
    {
        printf("0\n");
    }
    else 
    {
        printf("%lld\n", left);
    }

    free(r);
    free(d);
    free(s);
    free(t);
    return 0;
}